package com.mvvm.ktnet.ui.drag

import android.os.Bundle
import android.widget.FrameLayout
import com.android.ktx.context.dp
import com.android.ktx.view.onClick
import com.mvvm.ktnet.R
import com.mvvm.ktnet.base.myappbase.BaseDbActivity
import com.mvvm.ktnet.base.viewmodel.BaseViewModel
import com.mvvm.ktnet.databinding.AcTestDragBinding
import com.mvvm.ktnet.ui.DragScaleView
import com.mvvm.ktnet.ui.DragScaleViewKt

class TestDrag : BaseDbActivity<BaseViewModel, AcTestDragBinding>() {
    override fun layoutId(): Int = R.layout.ac_test_drag

    var num = 1

    override fun initView(savedInstanceState: Bundle?) {

        mDatabind.add.onClick {
            addScalview()
        }
    }

    private fun addScalview() {
        val dragScaleView = DragScaleViewKt(this)
        dragScaleView.setContent("view $num")
        dragScaleView.isClickable=true
        val lp = FrameLayout.LayoutParams(
            120.dp,
            120.dp
        )
        dragScaleView.layoutParams = lp

        num++
        val number = mDatabind.flRoot.childCount
        if (number > 0) {
            for (i in 0..number) {
                val view = mDatabind.flRoot.getChildAt(i)
                if (view != null && view is DragScaleViewKt) {
                    view.setTop(false)
                }
            }
        }
        mDatabind.flRoot.addView(dragScaleView)
        dragScaleView.setTop(true)
    }

    override fun createObserver() {

    }

    override fun initData() {

    }
}